<?PHP
/*
 * $Id: TimestampAction.class.php 171 2009-12-16 16:08:26Z namba0219 $
 * =============================================================================
 * Barge - Web application framework on PHP5
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * =============================================================================
 * For more information, see http://barge.googlecode.com/
 */
namespace admin\actions;

use \DateTime;

use barge\System;
use barge\io\File;
use barge\utils\ArrayList;
use barge\utils\HashMap;
use barge\utils\FileUtils;
use barge\utils\OutputBuffer;
use barge\utils\String;
use barge\utils\Timestamp;
use barge\web\ActionContext;
use barge\web\DispatchAction;
use barge\web\Cookie;
use barge\web\Request;
use barge\web\Response;
use barge\web\Messages;
use barge\web\Message;
use barge\web\Validator;

/**
 * @version 1.0 2009/01/24
 * @author Kenji Namba
 * @see DispatchAction
 */
class TimestampAction extends DispatchAction
{
	/**
	 * @param ActionContext $context
	 * @see Action#execute
	 */
	public function init(ActionContext $context)
	{
		/* @var $form TimestampForm */
		$form = $context->getForm(false);

		$form->setDate(System::currentTime()->format("Y/m/d H:i:s"));

		$context->render();
	}

	/**
	 * @param ActionContext $context
	 * @see Action#execute
	 */
	public function save(ActionContext $context)
	{
		/* @var $form TimestampForm */
		$form = $context->getForm(false);
		if (String::isNotEmpty($form->getDate())) {
			System::setCurrentTime(new DateTime($form->getDate()));
		}
		$context->render();
	}

	/**
	 * @param ActionContext $context
	 * @see Action#execute
	 */
	public function reset(ActionContext $context)
	{
		$form = $context->getForm(false);
		System::setTimeOffset(0);
		$context->render();
	}

	/**
	 * @return ArrayList
	 */
	protected function getMethods()
	{
		return new ArrayList('save', 'reset');
	}

}
